//author:jxx
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
  components: {//动态扩充组件或组件路径
    //表单header、content、footer对应位置扩充的组件
    gridHeader: '',//{ template: "<div>扩展组xx件</div>" },
    gridBody: '',
    gridFooter: '',
    //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
    modelHeader: '',
    modelBody: '',
    modelFooter: ''
  },
  buttons: { view: [], box: [], detail: [] },//扩展的按钮
  methods: {//事件扩展
    onInit() {
      this.ck = false;
      this.single = true
      this.pagination.sortName = "createDate";  //设置排序字段
      this.pagination.order = "asc"; //排序方式desc或者asc
      this.load = false
      //设置主表合计
      this.summary = true;
      //this.searchFormFields.order_number='HB22020735899965';
      this.searchFormFileds.takeTime = [this.getStartDate(), this.getEndDate()]
      //var time1= relativeTimeThreshold();
      //var start = relativeTimeThreshold(time1).add(-1, 'day');
      // var end = relativeTimeThreshold(time1).add(-1, 'day');
      //console.log(this.getStartDate(-1),this.getEndDate(-1));
      //this.searchFormFields.createDate='2022-01-18 00:00:00,2022-01-19 00:00:00'
      this.const.PAGE= 'GetPageDataChildren' 
    },
    destroyed () {
      this.const.PAGE = 'getPageData'
    },
    rowClick({ row, column, event }) { //查询界面table点击行选中当前行
      this.$refs.table.$refs.table.toggleRowSelection(row);
      return true;
    },
    onInited() {
      //设置主表求字段，后台需要实现SummaryExpress方法
      this.columns.forEach(x => {
        if (x.field == 'settlement_total_fee') {
          x.summary = true;
        }
      })
    },

    UtilHandleBigData(data, callback, pageSize = 20) {
      let totalCount = data.length; // 共多少条
      let currentPageNumber = 1; // 当前页数
      let totalPageNumer = Math.ceil(totalCount / pageSize); //可分多少页,就是分割为多少个小数组
      let handler = () => {
        let start = (currentPageNumber - 1) * pageSize;
        let end = currentPageNumber * pageSize;
        let currentData = data.slice(start, end); // 当前页的数据
        if (typeof callback === "function") {
          callback(currentData, {
            totalCount,
            totalPageNumer,
            currentPageNumber,
            pageSize,
          });
        }
        if (currentPageNumber < totalPageNumer) {
          window.requestAnimationFrame(handler);
        }
        currentPageNumber++;
      };
      handler();
    },
    getStartDate(dates) {
      var dd = new Date();
      var n = dates || 0;
      dd.setDate(dd.getDate() + n);
      var y = dd.getFullYear();
      var m = dd.getMonth() + 1;
      var d = dd.getDate() - 1;
      m = m < 10 ? "0" + m : m;
      d = d < 10 ? "0" + d : d;
      var day = y + "-" + m + "-" + d + " 00:00:00";
      return day;
    },
    getEndDate(dates) {
      var dd = new Date();
      var n = dates || 0;
      dd.setDate(dd.getDate() + n);
      var y = dd.getFullYear();
      var m = dd.getMonth() + 1;
      var d = dd.getDate() - 1;
      m = m < 10 ? "0" + m : m;
      d = d < 10 ? "0" + d : d;
      var day = y + "-" + m + "-" + d + " 23:59:59";
      return day;
    }
  }
};
export default extension;